#include "sqlist.h"

void swap(ElemType* a, ElemType* b) {
    ElemType temp = *a;
    *a = *b;
    *b = temp;
}

#ifdef REVERSE_WHOLE_LIST
// 整体逆置
void ReverseList(SqList* l) {
    for (int i = 0, j = l->length - 1; i < j; ++i, --j) {
        swap(&l->data[i], &l->data[j]);
    }
}

#else
// 部分逆置
bool ReverseList(SqList* l, int start, int end) {
    if (start < 0 || end >= l->length || start >= end) {
        return false;
    }
    for (int i = start, j = end; i < j; ++i, --j) {
        swap(&l->data[i], &l->data[j]);
    }
    return true;
}
#endif

int main() {

#ifdef REVERSE_WHOLE_LIST
// 测试整体逆置功能
    SqList la;
    ElemType a[] = {1, 3, 5, 7, 9, 11};
    CreateList(&la, a, 6);
    PrintList(&la);
    ReverseList(&la);
    PrintList(&la);
#else
// 测试部分逆置功能
    SqList lb;
    ElemType b[] = {2, 4, 6, 8, 10};
    CreateList(&lb, b, 5);
    PrintList(&lb);
    ReverseList(&lb, 0, 2);
    PrintList(&lb);
#endif
    return 0;
}